package lxt.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lxt.dao.InvoiceInfoDao;
import lxt.dao.InvoiceOrderDao;
import lxt.entity.InvoiceInfo;
import lxt.service.InvoiceInfoService;

public class InvoiceInfoServiceImpl implements InvoiceInfoService {
	private InvoiceInfoDao invoiceInfoDao;
	private InvoiceOrderDao invoiceOrderDao;

	public boolean addInvoiceInfo(InvoiceInfo invoiceInfo) throws Exception {
		this.invoiceInfoDao.save(invoiceInfo);
		return true;
	}

	public List<Object> queryInvoiceInfoById(String orderId)
			throws Exception {
		return this.invoiceInfoDao.queryInvoiceInfoById(orderId);
	}
	/**
	 * 派单查询
	 */
	public List<Object> queryDistribute(String order,String truckId,int offset, int length)throws Exception{
		List<Object> ob = new ArrayList<Object>();
		List<String> orders = this.invoiceOrderDao.queryInvosOrderId(order,offset,length);
		int total = this.invoiceOrderDao.loadInvosOrderIdCount(order);
		
		for(int i=0;i<orders.size();i++){
			Map<String,Object> map = new HashMap<String, Object>();
			String orderId = orders.get(i);
			List<Object> list = this.invoiceInfoDao.queryDistribute(orderId,truckId);
			if(list.size()>0){
				map.put("tab1", orderId);
				map.put("tab2", list);
				ob.add(map);
			}
		}
		ob.add(total);
		return ob;
	}
	/**
	 * get set
	 * @return
	 */
	public InvoiceInfoDao getInvoiceInfoDao() {
		return invoiceInfoDao;
	}

	public void setInvoiceInfoDao(InvoiceInfoDao invoiceInfoDao) {
		this.invoiceInfoDao = invoiceInfoDao;
	}

	public InvoiceOrderDao getInvoiceOrderDao() {
		return invoiceOrderDao;
	}

	public void setInvoiceOrderDao(InvoiceOrderDao invoiceOrderDao) {
		this.invoiceOrderDao = invoiceOrderDao;
	}
	
}
